import pickle
d = dict(name='Bob', age=20, score=88)
# pickle.dumps()方法把任意对象序列化成一个bytes
print(pickle.dumps(d))
f = open('dump.txt', 'wb')
# pickle.dump()直接把对象序列化后写入一个file-like Object
pickle.dump(d, f)
f.close()
f = open('dump.txt', 'rb')
# pickle.loads()方法反序列化出对象
d1 = pickle.load(f)
f.close()
print(d1)